Micron Document




Inheritance (object-oriented programming)
part 8/28 · 45.4 KB total
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
The colon indicates that the subclass inherits from the superclass. The visibility modifier is optional and, if present, may be either private or public. The default visibility (if there is no modifier present) is private. Visibility specifies whether the features of the base class are privately derived or publicly derived.

Note that in some other languages like Java and C#, there is no visibility modifier for inheritance:

// No visibility modifier
// Equivalent to public SuperClass in C++
class SubClass extends SuperClass {
// subclass members
}

Some languages also support the inheritance of other constructs. For example, in Eiffel, contracts that define the specification of a class are also inherited by heirs. The superclass establishes a common interface and foundational functionality, which specialized subclasses can inherit, modify, and supplement. The software inherited by a subclass is considered reused in the subclass. A reference to an instance of a class may actually be referring to one of its subclasses. The actual class of the object being referenced is impossible to predict at compile-time. A uniform interface is used to invoke the member functions of objects of a number of different classes. Subclasses may replace superclass functions with entirely new functions that must share the same method signature.

Non-subclassable classes

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────